package com.lin.controller;
import com.lin.entity.User;

import com.lin.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
public class UserController {
    @Autowired
    IUserService iUserService;


    @GetMapping(value = "/info",produces = {"application/json;charset=UTF-8"})
    public List<User> listUserInfo(){
        return iUserService.listUser();
    }


    @GetMapping(value = "/info/{id}",produces = {"application/json;charset=UTF-8"})
    public User UserInfoById(@PathVariable(value = "id")Integer id){
        return iUserService.selectUserById(id);
    }


    @PostMapping(value = "/add",produces = {"application/json;charset=UTF-8"})
    public void addUser(@RequestBody User user){
        iUserService.insertUser(user);
    }


    @PostMapping(value = "/remove/{id}",produces = {"application/json;charset=UTF-8"})
    public void removeUser(@PathVariable("id") Integer id){
        iUserService.deleteUserById(id);
    }


    @PostMapping(value = "/edit",produces = {"application/json;charset=UTF-8"})
    public void editUser(@RequestBody User user
    ){
        iUserService.updateUser(user);
    }

}